<?php
require("../IncludeManager.php");
using("Utils_Xml_Parser");
using("Utils_ResourceManager");
using("Utils_ReflectionFacade");
using("Tests_Files_Catalog");

class Junction_Builder {
	
	/**
	 * XML parser
	 *
	 * @var Utils_Xml_Parser
	 */
	private $_parser;
	
	public function __construct() {
		try {
			$this->_parser = new Utils_Xml_Parser();
			$resource = new Utils_ResourceManager($this);
			foreach ($resource as $key) {
				$this->_parser->setHandler($key, Utils_ReflectionFacade::getInstance($resource->getString($key), array()));
			}
		} catch (Utils_Exceptions_Reflection $e) {
			throw $e;
		} catch (Utils_Exceptions_Resource $e) {
			throw $e;
		}
	}
	
	public function build($file) {
		$stack = $this->_parser->parseFile($file);
		$class = $stack->pop();
		while ($stack->size() > 0) {
			$class->setProperty($stack->pop());
		}
		echo $class;
	}
}

$builder = new Junction_Builder();
$builder->build(Tests_Files_Catalog::fetch("test.xml"));
?>